package com.llkj.qingnianguoxue.mine;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.base.BaseActivity;
import com.llkj.qingnianguoxue.http.HttpMethod;
import com.llkj.qingnianguoxue.util.StringUtils;
import com.llkj.qingnianguoxue.util.ToastUtil;

/**
 * 意见反馈
 */
public class FeedBackActivity extends BaseActivity implements View.OnClickListener, TextWatcher {
    private EditText etRemarks;//备注
    private TextView tvLength;
    private TextView btnSubmit;//提交

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
        setTitle("意见反馈", true, TITLE_TYPE_IMG, R.drawable.icon_back, false, -1, -1);

        initView();
        initListener();
    }

    private void initView() {
        initStatusbar(TSATUSBAR_TYPE_BLACK_TEXT,rlTitle,R.color.gray_bar);
        etRemarks = (EditText) findViewById(R.id.et_remarks);
        tvLength = (TextView) findViewById(R.id.tv_length);
        btnSubmit = (TextView) findViewById(R.id.tv_submit);
    }

    private void initListener() {
        btnSubmit.setOnClickListener(this);
        etRemarks.addTextChangedListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_submit:

                String mail = etRemarks.getText().toString().trim();
                if (StringUtils.isEmpty(mail)) {
                    ToastUtil.makeLongText(this, getString(R.string.input_feed_back));
                    return;
                }

                loadWaitDialog();
                HttpMethod.feedback(this, this, mail);

                break;
        }
    }

    @Override
    protected void onhttpSuccess(String data, int method) {
        super.onhttpSuccess(data, method);
        if (method == HttpMethod.HTTP_USER_FEEDBACK) {
            setResult(RESULT_OK);
            myFinish();
        }
    }

    @Override
    protected void myToast() {
        super.myToast();
        ToastUtil.makeLongText(this, "反馈成功");
    }

    @Override
    protected void onhttpFailed(String message, int method) {
        super.onhttpFailed(message, method);
        if (!StringUtils.isEmpty(message)) {
            ToastUtil.makeLongText(this, message);
        }
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (s.length() > 200) {
            tvLength.setTextColor(getResources().getColor(R.color.colorB93A3C));
            btnSubmit.setSelected(true);
            btnSubmit.setClickable(false);
        } else {
            tvLength.setTextColor(getResources().getColor(R.color.color999999));
            btnSubmit.setSelected(false);
            btnSubmit.setClickable(true);
        }
        tvLength.setText(String.format(getResources().getString(R.string.input_length_200), s.length()));
    }

    @Override
    public void afterTextChanged(Editable s) {
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }
}
